package Controller.Actions.Modify;

import Controller.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import Model.Beans.Results.*;
import Model.Beans.*;
import Model.QBE.*;

public class ModifyCourseAction implements Action {
    
    private String name;
    
    public ModifyCourseAction() 
    {
        this.name = "ModifyCourse";
    }
    
    public String getName()
    {
        return name;
    }
    
    public void perform(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        CourseModel cmodel = new CourseModel();
        ProfessorModel pmodel = new ProfessorModel();
        ClassroomModel clmodel = new ClassroomModel();
        
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        String code_course = request.getParameter("code");
        String professor_id = request.getParameter("professor");
        String classroom_id = request.getParameter("classroom");
        String days = request.getParameter("days");
        String hour = request.getParameter("hour");
            
                response.setContentType("text/xml");
        response.setHeader("Cache-Control", "no-cache");
        
        Course course = new Course(Integer.parseInt(id), clmodel.search_by_id(classroom_id), days, code_course, pmodel.search_by_id(professor_id), hour, name);
        if(cmodel.modify(course) != 0)
        {
            response.getWriter().write("<message> The course " + course.toString() +  " has been successfully modified </message>");
        }
        else
        {
            response.getWriter().write("<message>The course doesn't exists </message>");
        }
    }
}
